<template>
	<view class="rechargePage">
		<view class="rechargePageCon">
			<view class="rechargePageConH">
				<text @click="prev">X</text>
				<text>请输入支付密码</text>
				<text></text>
			</view>
			<view class="rechargePageConC">
				<text>预约挂号</text>
				<text>
					￥
					<text>{{ Data.money }}.00</text>
				</text>
			</view>
			<view class="rechargePageConF">
				<text>支付方式</text>
				<view>
					<text>余额</text>
					<text>></text>
				</view>
			</view>
			<view class="rechargePageConB">
				<view v-for="(v, index) in [0, 1, 2, 3, 4, 5]">
					<text>{{ Data.password.split('')[index] }}</text>
				</view>
				<input type="number" v-model="Data.password" @input="inpFu" maxlength="6" />
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		reactive,
		onMounted
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		onlinepayPay,
		hospitalizationPay
	} from '@/api/TopUpService.js';
	import {
		useTopStore
	} from '@/store/TopUpService.js';
	const topStore = useTopStore();
	const Data = reactive({
		password: '',
		money: 0,
		id: 0
	})
	const onlinepay = (fun) => {
		let payData = {
			rechargeMoney: Data.money,
			userId: topStore.userId,
			id: Data.id,
			payPwd: Data.password
		}
		let pay = onlinepayPay(payData);
		if (topStore.topType == "hospital") {
			payData = {
				rechargeMoney: Data.money,
				userId: topStore.userId,
				id: Data.id,
				pwd: Data.password
			}
			pay = hospitalizationPay(payData)
		}
		pay.then(res => {
			if (res.data.msg == "success" && res.data.data != '支付密码错误') {
				fun && fun()
			} else {
				uni.hideLoading();
				uni.showToast({
					title: '支付失败',
					duration: 1000,
					icon: 'error'
				});
			}
		}).catch(err => {
			console.log(err)
		})
	}
	const inpFu = () => {
		if (Data.password.length == 6) {
			uni.showLoading({
				title: '支付中',
				mask: true,
			});
			setTimeout(() => {
				onlinepay(() => {
					uni.hideLoading();
					uni.navigateTo({
						url: `/pages/selfPayment/successfulPayment/successfulPayment?money=${Data.money}&id=${Data.id}`

					})
				}, 1000)
			});

		}
	}
	const prev = () => {
		uni.navigateBack({
			delta: 1
		})
	}
	onMounted(() => {})
	onLoad(option => {
		Data.money = parseFloat(option.money);
		Data.id = parseFloat(option.id);
	})
</script>

<style lang="less" scoped>
	.rechargePage {
		width: 750rpx;
		height: 100vh;
		background-color: #969697;
		padding-top: 140rpx;

		.rechargePageCon {
			width: 640rpx;
			height: 550rpx;
			border-radius: 20rpx;
			background-color: #ffffff;
			margin: 0 auto;

			.rechargePageConH {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-weight: 500;
				width: 100%;
				height: 100rpx;
				padding: 0 45rpx;
				box-sizing: border-box;
				font-size: 35rpx;

				text:first-child {
					font-weight: 600;
					color: #f2f2f2;
				}
			}

			.rechargePageConC {
				width: 570rpx;
				margin: 0 auto;
				height: 200rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				border-bottom: 1px solid #f2f2f2;

				text:first-child {
					font-weight: 500;
					font-size: 35rpx;
				}

				text:last-child {
					font-weight: 600;

					text {
						font-size: 50rpx;
					}
				}
			}

			.rechargePageConF {
				width: 570rpx;
				height: 70rpx;
				margin: 0 auto;
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 30rpx;
				font-weight: 600;
				color: #aaacae;

				view {
					text:first-child {
						color: black;
						margin: 0 20rpx;
					}
				}
			}

			.rechargePageConB {
				width: 570rpx;
				height: 90rpx;
				margin: 30rpx auto;
				border: 1px solid #f2f2f2;
				position: relative;
				display: flex;
				box-sizing: border-box;

				view {
					flex: 1;
					border: 1px solid #f2f2f2;
					background-color: #fff;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 30rpx;
					font-weight: 600;
				}

				input {
					width: 100%;
					height: 100%;
					color: transparent;
					overflow: hidden;
					position: absolute;
					left: 0;
					top: 0;
					background-color: transparent;
					opacity: 0;
				}
			}
		}
	}
</style>
